var Id=0,type=0;
var loadInfo = 0;
layui.use(['layer'],function () {
    Id = GetQueryString("Id");
    type = sessionStorage.getItem("type");
    if(!isNotNull(Id)){
        Id = 0
    }else{
        let tempName="";
        if(type==38){//茶文化
            tempName="/getFindArticleById";
        }else if(type==39){//茶言说
            tempName="/getFindSelectedkById";
        }else if(type==40){//茶精选
            tempName="/getFindSelectedkById";
        }
        SelectActicleListById(tempName);
    };
    // selectFindDetailsInfoByIdPc();//查询发表及文章详情
    initComment();//查询评论
});
function SelectActicleListById(tempName) {
    $.ajax({
        url: httpurl + tempName,
        cache: false,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType : 'application/json',
        data: {
            "id": Id,
        },
        success: function (data) {
            if (data.rtnCode == 200) {

                let dataInfo = data.data;
                $(".article_content .title").html(dataInfo.title);
                $(".article_content .content").html(dataInfo.context);
                if(isNotNull(dataInfo.images))
                select_img_list(dataInfo.images);
                if(type==38){

                    // UE.getEditor('container').setContent(dataInfo.context);//商品描述
                    // form.render();
                    // $("#title").val(dataInfo.title);
                    // $("#sort").val(dataInfo.sort);
                    //

                }else if(type==39 || type==40){
                    // $('input:radio[name="state"][value="' + dataInfo.disable + '"]').attr('checked', 'true');
                    // UE.getEditor('container').setContent(dataInfo.context);
                    // form.render();
                    // $("#title").val(dataInfo.title);
                    // $("#sort").val(dataInfo.sort);
                    if(isNotNull(dataInfo.video)){
                        select_vode_list(dataInfo.video);
                    }
                    // if(isNotNull(dataInfo.image))
                    //     select_img_list(dataInfo.image);
                }

                // if(isNotNull(dataInfo.pidjson))listId=dataInfo.pidjson.split(",");
            }
        }
    })
}
function select_img_list(imgList) {
    let infos = "";
    if (imgList.length > 0) {
        let imgArr = imgList.split(",");
        for (let i = 0; i < imgArr.length; i++) {
            infos+='<li><a href="javascript:;"><img class="" src="' + imgArr[i] + '"></a></li>';
        }
    }
    $(".photosList").html(infos);
}
function select_vode_list(videoList) {
    console.log(videoList);
    let infos = "";
    if (videoList.length > 0) {
        let videoArr = videoList.split(",");
        for (let i = 0; i < videoArr.length; i++) {
            infos+='<li><a href="javascript:;"><video class="" src="' + videoArr[i] + '" controls="controls"></video></a></li>';
        }
    }
    $(".videoList").html(infos);
}
function selectFindDetailsInfoByIdPc() {
    $.ajax({
        url: httpurl + "/selectFind",
        cache: false,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType : 'application/json',
        data: {
            "id": Id,
        },
        success: function (data) {
            if (data.rtnCode == 200) {
                var dataInfo = data.data;
                var presenters=(dataInfo.presenters==0?"用户":(dataInfo.presenters==1?"品牌店铺":"官方平台"));
                if(dataInfo.presenters==0){//用户
                    var headimg = (dataInfo.spUserEntity == null ? "" : (dataInfo.spUserEntity.uimg == null ? dataInfo.spUserEntity.headimg : (visitimgurl + "/" + dataInfo.spUserEntity.uimg)));
                    var username = (dataInfo.spUserEntity == null ? "" : (dataInfo.spUserEntity.username == null ? dataInfo.spUserEntity.username : dataInfo.spUserEntity.username));
                    $(".layadmin-homepage-pad-img").attr("src",headimg);
                    $(".title").html(username);
                    $(".presenters").html(presenters);
                }else if(dataInfo.presenters==1){//店铺
                    $(".layadmin-homepage-pad-img").attr("src",visitimgurl+"/"+(dataInfo.brandInfoEntity==null?"":dataInfo.brandInfoEntity.logo));
                    $(".title").html(dataInfo.brandInfoEntity==null?"":dataInfo.brandInfoEntity.name);
                    $(".presenters").html(presenters);
                }else {//官方平台
                    $(".layadmin-homepage-pad-img").attr("src","../../images/logo.png");
                    $(".title").html("九航云选");
                    $(".presenters").html(presenters);
                }
                $(".article_content p").html(dataInfo.content);
                $(".praisenum").html(dataInfo.praisenum);
                $(".downloadnum").html(dataInfo.downloadnum);
                $(".commentsnum").html(dataInfo.commentsnum);
                $(".sharenum").html(dataInfo.sharenum);
                $(".newintime").html(dataInfo.intime);
                var split = dataInfo.img.split(";");
                var info = "";
                for (var i = 0; i < split.length; i++) {
                    info+='<li>' +
                            '<a href="javascript:;">' +
                            '<img class="" src="' + visitimgurl + "/" + split[i] + '">' +
                            '</a>' +
                            '</li>';
                }
                $(".photosList").html(info);
            }


        }
    });
}


function initComment() {
    $.ajax({
        url: httpurl + "/callMessage",
        cache: false,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType : 'application/json',
        data: {
            "id": Id,
            "type": type,
            "page": pageNo,
            "pageSize": pageSize,
        },
        success: function (data) {
            if (data.rtnCode == 200) {
                var info = "";
                var initdata = data.data;
                var dataInfo = initdata.list;
                totalRecords = initdata.total;

                for (var i = 0; i < dataInfo.length; i++) {
                    var headimg = (dataInfo[i].spUserEntity == null ? "" : (dataInfo[i].spUserEntity.uimg == null ? dataInfo[i].spUserEntity.headimg : (visitimgurl + "/" + dataInfo[i].spUserEntity.uimg)));
                    var username = (dataInfo[i].spUserEntity == null ? "" : (dataInfo[i].spUserEntity.username == null ? dataInfo[i].spUserEntity.username : dataInfo[i].spUserEntity.username));
                        info += '<div class="comment">' +
                        '            <div class="conmment_details">' +
                        '            <div class="imgdiv">' +
                        '                <img class="imgcss"  src="' + headimg + '"/>' +
                        '            </div>' +
                        '                <div class="width50" style="float:left;">' +
                        '                    <span class="comment_name">' + username + '</span><span class="margin_left2b">' + dataInfo[i].newintime + '</span>' +
                        '                </div>' +
                        '                <div class="del">' +
                        '                    <span  class="show_reply_list" onclick="show_reply_list(this);">查看回复</span>' +
                        '                    <i class="icon layui-icon" >&#xe6c6;赞(' + dataInfo[i].num + ')</i>' +
                        '                    <a class="del_comment" data-id="' + dataInfo[i].id + '" data-info="deleteFindRecordById" onclick="DeleteInfo(this)"> <i class="icon layui-icon" >&#xe640;删除</i></a>' +
                        '                </div>' +
                        '                <div class="comment_content" >' + dataInfo[i].content + '</div>' +
                        '            </div>' +
                        '            <div class="reply_list"  >';
                    var findRecords = dataInfo[i].findRecords;
                    var infos = "";
                    var tempInfo = "查看剩下的回复";
                    if (findRecords.length > 0) {
                        for (var j = 0; j < findRecords.length; j++) {
                            var username = (findRecords[j].spUserEntity == null ? "" : (findRecords[j].spUserEntity.username == null ? findRecords[j].spUserEntity.username : findRecords[j].spUserEntity.username));
                            infos += '                <div class="reply" >' +
                                '                    <span class="reply_name">' + username + '</span>：<span class="reply_content">' + findRecords[j].content + '</span>' +
                                '                    <a  data-id="' + findRecords[j].id + '" data-info="deleteFindRecordById" onclick="DeleteInfo(this)" class="del_reply">' +
                                '                        <i class="icon layui-icon " >删除</i>' +
                                '                    </a>' +
                                '                </div>';
                        }
                    } else {
                        tempInfo = "沒有任何回复數据";
                    }
                    info += infos + '</div>' +
                        '            <div class="show_remain_reply">' + tempInfo + '</div>' +
                        '            <!--回复列表结束-->' +
                        '        </div>' +
                        '        <hr>';
                }
                if (dataInfo.length < pageRecords) {
                    loadInfo = 1;
                    $(".comment_add_or_last").html("没有更多评论了");
                } else {
                    $(".comment_add_or_last").html("点击加载更多评论");
                }
                $(".comment_list").append(info);


            } else {
                loadInfo = 1;
                $(".comment_add_or_last").html("没有更多评论了");
            }
        }
    });
}

function loadMore() {
    if (loadInfo == 1) {
        top.layer.alert("沒有更多评论了...");
        return;
    }
    pageNo++;
    initComment();
}